<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 20:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_Ticket" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>票务管理系统</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }
        table th, table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        table tr:nth-child(even) {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h2>票务管理系统</h2>

<!-- 查询表单 -->
<form action="index.jsp" method="get">
    <select name="conditionColumn">
        <option value="id">票务ID</option>
        <option value="oid">订单ID</option>
        <option value="uid">用户ID</option>
    </select>
    <input type="text" name="conditionValue" placeholder="输入查询值">
    <input type="submit" value="查询">
</form>

<!-- 显示票务列表 -->
<table>
    <thead>
    <tr>
        <th>票务ID</th>
        <th>订单ID</th>
        <th>用户ID</th>
        <th>座位</th>
        <th>票务状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        DB_Ticket dbTicket = new DB_Ticket();
        String conditionColumn = request.getParameter("conditionColumn");
        if (conditionColumn == null) {
            conditionColumn = "";
        }
        String conditionValue = request.getParameter("conditionValue");
        if (conditionValue == null) {
            conditionValue = "";
        }
        List<String> returnList = new ArrayList<>();
        dbTicket.find(conditionColumn, conditionValue, returnList);
        for (int i = 0; i < returnList.size(); i += 5) {
    %>
    <tr>
        <td><%= returnList.get(i) %></td>
        <td><%= returnList.get(i + 1) %></td>
        <td><%= returnList.get(i + 2) %></td>
        <td><%= returnList.get(i + 3) %></td>
        <td><%= returnList.get(i + 4) %></td>
        <td>
            <a href="editTicket.jsp?id=<%= returnList.get(i) %>">编辑</a>
            <a href="deleteTicket.jsp?id=<%= returnList.get(i) %>">删除</a>
        </td>
    </tr>
    <% } %>
    </tbody>
</table>

<!-- 添加票务表单 -->
<h2>添加票务</h2>
<form action="addTicket.jsp" method="post">
    <label for="oid">订单ID:</label>
    <input type="text" id="oid" name="oid" required><br>
    <label for="uid">用户ID:</label>
    <input type="text" id="uid" name="uid" required><br>
    <label for="set">座位:</label>
    <input type="text" id="set" name="set" required><br>
    <input type="submit" value="添加票务">
</form>
</body>
</html>